﻿namespace ufida.u9.ait.openapi
{
	using System;
	using System.Collections.Generic;
	using System.Text;
    using ufida.u9.ait.openapi.utils;
    using UFIDA.U9.CBO.Pub.Controller;
    using UFIDA.U9.PPR.PurPriceList;
    using UFSoft.UBF.AopFrame;
    using UFSoft.UBF.Business;
    using UFSoft.UBF.Util.Context;

	/// <summary>
	/// PurPriceListDelete partial 
	/// </summary>	
	public partial class PurPriceListDelete 
	{	
		internal BaseStrategy Select()
		{
			return new PurPriceListDeleteImpementStrategy();	
		}		
	}
	
	#region  implement strategy	
	/// <summary>
	/// Impement Implement
	/// 
	/// </summary>	
	internal partial class PurPriceListDeleteImpementStrategy : BaseStrategy
	{
		public PurPriceListDeleteImpementStrategy() { }

		public override object Do(object obj)
		{						
			PurPriceListDelete bpObj = (PurPriceListDelete)obj;

			try
			{
				if (bpObj.Data == null || bpObj.Data.Count == 0)
					throw new Exception("传入参数为空");

				List<CommonArchiveDataDTOData> retlist = new List<CommonArchiveDataDTOData>();

				foreach (var dto in bpObj.Data)
				{
					PurPriceList item = PurPriceList.Finder.Find($"Code='{dto.Code}'");
					if (item == null)
					{
						//新增逻辑
						throw new Exception($"单号:[{dto.Code}]不存在,不能审核!");

					}
					else
					{
						//修改逻辑
						using (ISession se = Session.Open())
						{
							item.Remove();

							se.Commit();
						}
					}

					retlist.Add(new CommonArchiveDataDTOData
					{
						ID = item.ID,
						Code = item.Code
					});
				}
				return ResultUtils.success(bpObj, bpObj.Data, retlist);
			}
			catch (Exception ex)
			{
				return ResultUtils.error(bpObj, bpObj.Data, ex);
			}
		}		
	}

	#endregion
	
	
}